<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" />

    <link href="/public/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/admin/css/ratuo.css" rel="stylesheet">

    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/public/admin/js/myFormValidate.js"></script>
    <script src="/public/admin/js/common.js"></script>
    <script src="/public/admin/js/myAjax.js"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/admin/js/jquery.validate.js"></script>

</head>
<body>
<div class="wrapper">
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <nav class="navbar navbar-default">
                            <div class="collapse navbar-collapse">
                                <form class="navbar-form form-inline" action="{:url('Admin/index')}" method="post">
                                    <div class="form-group pull-left">
                                       <!-- <a href="javascript:void(0);" onclick="openLayer('{:url("Admin/admin_info")}','添加权限')" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加权限</a>-->
                                        <a href="javascript:void(0);" onclick="add()" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加权限</a>
                                    </div>
                                </form>
                            </div>
                        </nav>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="list-table" class="table table-bordered table-striped dataTable">
                                    <thead>
                                    <tr role="row" style="font-weight: bold;" align="center">
                                        <td>ID</td>
                                        <td>权限名</td>
                                        <td>权限</td>
                                        <td>排序</td>
                                        <td>图标</td>
                                        <td>操作</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {foreach name="data" item="v"}
                                        <tr role="row" align="center">
                                            <td>{$v.id}</td>
                                            <td align="left"><?php echo $v['_name']; ?></td>
                                            <td>{$v['name']}</td>
                                            <td>
                                            <input style="text-align: center;" type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')"  onchange="updateSort('authRule','id','{$v.id}','sort',this)" size="4" value="{$v['sort']}" />
                                            </td>
                                            <td><i class="fa {$v['icon']}"></i></td>
                                            <td>
                                                <a href="javascript:;" ruleId="{$v['id']}" onclick="add_child(this)">添加子权限</a> |
                                                <a href="javascript:;" ruleId="{$v['id']}" ruleName="{$v['name']}" ruleTitle="{$v['title']}" ruleIcon="{$v['icon']}" onclick="edit(this)">修改</a> |
                                                <a href="javascript:;" onclick="del('{$v.id}')">删除</a>
                                            </td>
                                        </tr>
                                    {/foreach}
                                    </tbody>
                                    <tfoot>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>

<!-- 添加菜单模态框开始 -->
<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加权限
                </h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-inline" action="{:url('Admin/Rule/form')}" method="post">
                    <input type="hidden" name="pid" value="0">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <td width="15%">权限名：</td>
                            <td><input class="form-control" type="text" name="title" required></td>
                        </tr>
                        <tr>
                            <td>权限：</td>
                            <td style="font-size: 12px;">
                                <input class="form-control" type="text" name="name" required> 输入模块/控制器/方法即可 例如 Admin/User/index
                            </td>
                        </tr>
                        <tr>
                            <td>图标：</td>
                            <td style="font-size: 12px;">
                                <input class="form-control" type="text" name="icon" > 输入字体图标,参考网站：http://code.z01.com/
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-success" type="submit" value="添加">
                            </td>
                        </tr>
                    </table>

                </form>
            </div>
        </div>
    </div>
</div>
<!-- 添加菜单模态框结束 -->
<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改权限
                </h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-inline" action="{:url('Admin/Rule/form')}" method="post">
                    <input type="hidden" name="id">
                    <table class="table table-striped table-bordered table-hover table-condensed">
                        <tr>
                            <th width="15%">权限名：</th>
                            <td>
                                <input class="form-control" type="text" name="title" required>
                            </td>
                        </tr>
                        <tr>
                            <th>权限：</th>
                            <td style="font-size: 12px;">
                                <input class="form-control" type="text" name="name" required> 输入模块/控制器/方法即可 例如 Admin/User/index
                            </td>
                        </tr>
                        <tr>
                            <td>图标：</td>
                            <td style="font-size: 12px;">
                                <input class="form-control" type="text" name="icon" > 输入字体图标,参考网站：http://code.z01.com/
                            </td>
                        </tr>
                        <tr>
                            <th></th>
                            <td>
                                <input class="btn btn-success" type="submit" value="修改">
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 修改菜单模态框结束 -->

<script>


    function add(){
        $("input[name='title'],input[name='name']").val('');
        $("input[name='pid']").val(0);
        $('#bjy-add').modal('show');
    }

    // 添加子菜单
    function add_child(obj){
        var ruleId=$(obj).attr('ruleId');
        $("input[name='pid']").val(ruleId);
        $("input[name='title']").val('');
        $("input[name='name']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var ruleId=$(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        var ruleName=$(obj).attr('ruleName');
        var ruleIcon=$(obj).attr('ruleIcon');
        $("input[name='id']").val(ruleId);
        $("input[name='title']").val(ruletitle);
        $("input[name='name']").val(ruleName);
        $("input[name='icon']").val(ruleIcon);
        $('#bjy-edit').modal('show');
    }

    function del(id) {
        parent.layer.confirm('确定要删除?', function(){
            parent.layer.closeAll('dialog');
            $.ajax({
                url:"/index.php/Admin/Rule/del/id/"+id,
                success: function(v){
                    var v =  eval('('+v+')');
                    parent.layer.msg(v.msg, {icon: 1,time: 1000});
                    if(v.hasOwnProperty('status') && (v.status == 1))
                        window.location.href = location.href;
                }
            });
            return false;
        });
    }
</script>


</body>
</html>